//
//  MCChoiceView.m
//  HYYL
//
//  Created by menhao on 2018/5/21.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCChoiceView.h"


@interface MCChoiceView()
@property (nonatomic,weak) UIButton *lastBtn;
@end
@implementation MCChoiceView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    NSArray *titleAry = @[@"彩票专区",@"更多游戏"];
    for (NSInteger i = 0; i < titleAry.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:btn];
        [btn setTitle:titleAry[i] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(13)];
        [btn setTitleColor:[UIColor colorWithHexString:@"#444444"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithHexString:@"#3680D3"] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = CGRectMake(i*G_SCREENWIDTH* 0.5, 0, G_SCREENWIDTH* 0.5 - 0.5, self.bounds.size.height);
        btn.tag = 1001 + i;
        if (i == 0) {
            btn.selected = YES;
            self.lastBtn = btn;
        }
        
    }
    
    UIView *line = [[UIView alloc] init];
    [self addSubview:line];
    line.backgroundColor = [UIColor colorWithHexString:@"#EFEFEF"];
    line.frame = CGRectMake(G_SCREENWIDTH * 0.5 - 0.5, 0, 1, self.bounds.size.height);
    

}

- (void)layoutSubviews{
    [super layoutSubviews];
    if (self.lotteryBlock) {
        self.lotteryBlock();
    }
}
- (void)btnClick:(UIButton *)btn{
    if (btn.selected) {
        return;
    }
    btn.selected = YES;
    self.lastBtn.selected = NO;
    if (btn.tag == 1001) { //彩票专区
        if (self.lotteryBlock) {
            self.lotteryBlock();
        }
    } else { //棋牌专区
        if (self.qiPaiBlock) {
            self.qiPaiBlock();
        }
    }
    self.lastBtn = btn;
}
@end
